using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DataAccess.Mapping;
using Entity.StoreProcedure;
using Entity.Base;
namespace BusinessObjects.BO_Actions {
    public class BO_Actions<SP> where SP : SPBase {

        public static DataTable ExecuteAndReturnDataTable(SP _objSP) {
            StoreProcedure<SP> _action = new StoreProcedure<SP>();
            try {
                return _action.ExecuteSPAndReturnDataTable(_objSP, _objSP.GetType());
            } catch (Exception ex) {
                throw ex;
            }
        }

        public static DataTable ExecuteListDataAndReturnDataTable(List<SP> _listEntity) {
            DataTable objDT = new DataTable();
            foreach (SP _entity in _listEntity) {
                StoreProcedure<SP> _action = new StoreProcedure<SP>();
                try {
                    objDT = _action.ExecuteSPAndReturnDataTable(_entity, _entity.GetType());
                } catch (Exception ex) {
                    throw ex;
                }
            }
            return objDT;
        }

        public static bool ExecuteAndReturnBooleanValue(SP _objSP) {
            StoreProcedure<SP> _action = new StoreProcedure<SP>();
            try {
                return _action.ExecuteSP(_objSP, _objSP.GetType());
            } catch (Exception ex) {
                throw ex;
            }
        }

        public static bool ExecuteListDataAndReturnBooleanValue(List<SP> _listEntity) {
            foreach (SP _entity in _listEntity) {
                StoreProcedure<SP> _action = new StoreProcedure<SP>();
                try {
                    _action.ExecuteSP(_entity, _entity.GetType());
                } catch (Exception ex) {
                    throw ex;
                }
            }
            return true;
        }

        public static string ExecuteAndReturnStringValue(SP _objSP) {
            StoreProcedure<SP> _action = new StoreProcedure<SP>();
            try {
                return _action.ExecuteSPAndReturnString(_objSP, _objSP.GetType());
            } catch (Exception ex) {
                throw ex;
            }
        }

        public static string ExecuteListDataAndReturnStringValue(List<SP> _listEntity) {
            string strReturn = null;
            foreach (SP _entity in _listEntity) {
                StoreProcedure<SP> _action = new StoreProcedure<SP>();
                try {
                    strReturn = _action.ExecuteSPAndReturnString(_entity, _entity.GetType());
                } catch (Exception ex) {
                    throw ex;
                }
            }
            return strReturn;
        }
    }
}

